// pages/many/many.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    display: 'none',
    isCode:false,
    user: [
      {
        username: '',
        password: '',
        nikename:'',
      }
    ],
    sendUsers: [
      {
        username: '',
        password: '',
      }
    ],
    deleteUser:[{
       username:'',
       password:'',
    }],
    enc:'',
    e:'',
  },
  deleteInfo(){
    var that=this
    console.log(that.data.e)
    // for(var i=0 ;i<that.data.user.length;i++){
    //     console.log('delte  ',that.data.user[i])
    //   if(that.data.user[i].username==that.data.e){
    //     that.data.user=that.data.user.splice(i)

    //     // wx.clearStorage({
    //     //   success: (res) => {},
    //     // })
    //     // wx.setStorage({
    //     //   key:'userInfo',
    //     //   data:that.data.user
    //     // })
      
    //     console.log('delec1choice',that.data.user)
    //   }
    // }
    wx.clearStorage({
      success: (res) => {
        wx.showToast({
          title: '缓存删除完成',
        })
        
      },
    })
    
       
  },
  signUp() {
    var that=this
    wx.showToast({
      title: '签到',
    })
    wx.getStorage({
      key: 'userInfo',
      success(res) {
        console.log('signUp本地数据', res.data)
        
        console.log('signUp本地数据legth', res.data.length)
        // console.log('signUp本地数据...000', res.data[1])
        for(var i=0 ;i<res.data.length;i++){
          console.log('----',res.data[i].username)
          console.log('----',res.data[i].password)
          if(that.data.enc===''){
            wx.request({
              //http://localhost:8081/xxt/SignOnce/{username}/{password}?password=zxcasd&username=19854810175
              url: 'https://lovegcu.xyz/xxt/SignOnce/{username}/{password}?password='+res.data[i].password+'&username='+res.data[i].username,
              // data:{
              //     "password": that.data.password,
              //     "username": that.data.username,
              // },
              method:'POST',
              success(res){
                console.log('res    ',res)
                wx.showToast({
                  title: '提交成功',
                  icon:'success'
                })
              }
            })
          }else{
            console.log("-------------------")
           
            wx.request({
              url: 'https://lovegcu.xyz/xxt/getInfo/'+res.data[i].username+'/'+res.data[i].password   
              +'/'+that.data.enc,
              method:"GET",
              success(res){
                console.log('res',res)
                wx.showToast({
                  title: '提交成功',
                  icon:'success'
                })
              }
            })
            
          }
        }
    
      }
    })
  },
  myChange(e) {
    var that = this
    
    console.log('选择',e.detail.value)
    console.log(that.data.user)
    that.setData({
      e:e.detail.value
    })
    console.log('e',that.data.e)
  },
  changeSign:function(e){
    var that =this
    console.log('二维码签到选择',e.detail.value)
    that.setData({
      swithc1Checked : e.detail.value,
      display  : 'none '
      })
    console.log('data中的swithc1Checked',this.data.swithc1Checked)
  },
  onChangeShowState:function(e){
    console.log('二维码签到选择是',e.detail)
    var that =this
    that.setData({
      isCode : e.detail.value,
      display  : 'flex'
    })
    console.log('data中的enc',this.data.enc)
  },
  scanCode:function(){
    var that=this;
    wx.scanCode({
      success(res){
        console.log(res)
        that.setData({
          enc:res.result.slice(-32)
        })
        console.log(res.result)
        console.log('---that.data.enc',that.data.enc)
      }
    })
     
  },
  formSubmit(e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    if (e.detail.value.username === "" || e.detail.value.password === "" || e.detail.value.nikename=="") {
      wx.showToast({
        title: '请勿提交空内容',
        icon: 'error'
      })
    } else {
      var that = this
      let array0 = this.data.user;
      array0.push(e.detail.value)

      that.setData({
        user: array0
      })
      wx.showToast({
        title: '添加成功',
        icon: 'success'
      })
      wx.setStorage({
        key: 'userInfo',
        data: that.data.user
      }

      )
      console.log('本地存储的数据:', wx.getStorage({
        key: 'userInfo',
        success(res) {
          console.log('本地存储的数据', res.data)
        }
      }))

      console.log('data中的数据:', that.data.user)
    }

  }
  ,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this
    console.log("页面加载")
    wx.getStorage({
      key: 'userInfo',
      success(res) {
        console.log('onLoad', res.data)
        that.setData({
          user: res.data,
          deleteUser:res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('onShow', this.data)

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})